Page({
  data: {
    // currentDate: new Date().getTime(),
    // houseLayerVisible: false,
    // repairLayerVisible: false,
    // dateLayerVisible: false,
    // houseList: [
    //   { name: '北京西三旗花园1号楼 101' },
    //   { name: '北京东村家园3号楼 302' },
    //   { name: '北京育新花园3号楼 703' },
    //   { name: '北京天通苑北苑8号楼 403' },
    // ],
    // repairItem: [{ name: '水路卫浴' }, { name: '电路灯具' }, { name: '管道疏通' }, { name: '开锁换锁' }],
    // attachment: [
    //   { url: '/repair_pkg/static/uploads/attachment.jpg' },
    //   { url: '/repair_pkg/static/uploads/attachment.jpg' },
    // ],
    data:{
      houseInfo:'',
      repairItemName:'',
      appointment: '',
      houseList:[],
      repairItem: [],
    }
  },
  onLoad(){
    this.getHouseList(),
    this.getRepairItem()
  },
  async getHouseList(){
    const {code ,data,houseList}=await wx.http.get('/house')
    // console.log(data);
    if(code !==10000)
    return wx.utils.toast('获取房屋失败')
    this.setData({
      houseList
    })
  },
  async getRepairItem() {
    // 请求数据接口
    const { code, data: repairItem } = await wx.http.get('/repairItem')
    // 检测接口返回的数据
    if (code !== 10000) return wx.utils.toast('获取维修项目失败!')
    // 数据渲染
    this.setData({ repairItem })
  },
  selectHouse(ev) {
    // 获取用户选择房屋的名称
    const { name: houseInfo } = ev.detail
    // 页面中渲染
    this.setData({ houseInfo })
  },
  selectRepairItem(ev) {
    // 获取用户选择的维修项目名称
    const { name: repairItemName } = ev.detail
    // 页面中渲染
    this.setData({ repairItemName })
  },
  selectDate(ev) {
    this.setData({
      dateLayerVisible: false,
      appointment: wx.utils.formatDate(ev.detail),
    })
  },

  openHouseLayer() {
    this.setData({ houseLayerVisible: true })
  },
  closeHouseLayer() {
    this.setData({ houseLayerVisible: false })
  },
  openRepairLayer() {
    this.setData({ repairLayerVisible: true })
  },
  closeRepairLayer() {
    this.setData({
      repairLayerVisible: false,
    })
  },

  openDateLayer() {
    this.setData({ dateLayerVisible: true })
  },
  closeDateLayer() {
    this.setData({ dateLayerVisible: false })
  },
  goList() {
    wx.reLaunch({
      url: '/repair_pkg/pages/list/index',
    })
  },
})
